using System;
using System.Collections;

using DesignByContract;

namespace Outcoding.GraphGenerator.Entities {
    public abstract class DispatcherBase {
        protected Queue mQueue;

        public int Count {
            get {
                return mQueue.Count;
            }
        }

        protected bool mIsAutoFill;

        public DispatcherBase() {
            mQueue = new Queue();
            mIsAutoFill = false;
        }

        public void Clear() {
            mQueue.Clear();
        }

        public bool Contains(object item) {
            return mQueue.Contains(item);
        }

        public object Pop() {
            object dequeued = mQueue.Dequeue();
            if(mQueue.Count == 0 && this.mIsAutoFill)
                this.Fill();

            return dequeued;
        }

        public void Add(object item) {
            mQueue.Enqueue(item);
        }

        public object Peek() {
            return mQueue.Peek();
        }

        //fills the dispatcher
        protected abstract void Fill();
    }
}
